//index.js
import {
    Home
} from 'home-model.js';
import SafeRenderUtil from '../../utils/saveRender.js'
var home = new Home();
//获取应用实例
const app = getApp()

Page({
    data: {
        activeId: '',
        page: 1,
        size: 5,
        hasMore: false, //是否可以翻页
        activityList: [], //活动列表
        scrollNav: "", //展示活动
        searchShow: false,
        searchForm: false, //搜索弹出框
        goodsListShow: false, //是否显示搜索商品
        activityGoodsList: [],
        addCartShow: false, //是否显示加入购物车
        goodsHide: false, //是否展示商品列表
        cartParams: {
            ctrnum: 1,
            stockNum: 0,
            goodsSize: null
        }, //加入购物车的参数
        isShowPopup: false, //是否显示弹窗
        tip: "", //弹窗显示内容
        searchVal: "",
        first: false, //控制页面加载一次
        hasCoupon: null,
        cartNum: 0,
        isVip: 0,
        nowVideo: '',
    },
    onReady: function(res) {
        this.videoContext = wx.createVideoContext('myVideo')
    },

    onLoad: function(options) {
        let sessionId = wx.getStorageSync("sessionId");

        let activeId = options.id;
        //获取分享人的手机号
        // if (options && options.inviteCode) {
        //   wx.setStorageSync("inviteCode", options.inviteCode);
        // }
        console.log("home-options========", options);

        let storeNo = "S00000001";
        wx.setStorageSync('storeNo', storeNo);
        let userInfo = wx.getStorageSync('sessionId');
        this.setData({
            storeNo,
            userInfo,
            activeId
        })
        if (options && options.invitePhone) {
            console.log('通过会员邀请人手机号', options.invitePhone)
            wx.setStorageSync("invitePhone", options.invitePhone);
        }
        // 扫码进入
        if (options && options.scene) {
            var scene = decodeURIComponent(options.scene);
            if (scene != 'undefined' && scene != null) {
                var sceneList = scene.split(',');
                console.log('扫码进入，home二维码信息', sceneList)
                let activeId = sceneList[0];
                this.setData({
                    activeId
                })
                wx.setStorageSync('inviteCode', sceneList[1] ? sceneList[1] : '');
                if (sessionId !== "" && sceneList[1]) {
                    let params = {
                        inviteCode: sceneList[1] ? sceneList[1] : ''
                    }
                    // 绑定邀请码
                    home.bindInviteCodeByMiniProgram(params, res => {
                        console.log('会场通过代购二维码进来绑定邀请码', res)
                        if (res.status) {
                            console.log('会场绑定邀请码成功')
                        }
                    })
                }
                
            }
        }
        // 通过代购直接分享小程序进来inviteCode
        if (options && options.inviteDaigoCode) {
            let params = {
                inviteCode: options.inviteDaigoCode
            }
            // 代购推广使用
            wx.setStorageSync('inviteCode', options.inviteDaigoCode)
            console.log('通过代购直接分享小程序进来inviteCode', wx.getStorageSync('inviteCode'))
            if (sessionId !== "") {
                // 绑定邀请码
                home.bindInviteCodeByMiniProgram(params, res => {
                    console.log('会场通过代购直接分享小程序进来绑定邀请码', res)
                    if (res.status) {
                        console.log('会场绑定邀请码成功')
                    }
                })
            }
        }
        
        // 转会场操作
        if (options.type === 'change') {
            this.setData({
                changeType: true,
                dropDown: true,
                page: 1,
                title: options.title
            })
        }
        //如果没登录需要跳转到登录页面
        if (sessionId === "") {
            wx.redirectTo({
                url: '/pages/getUserInfo/getUserInfo?path=/pages/home/home&id=' + activeId,
            })
            return
        }
        app.aldstat.sendEvent('店铺首页');
        wx.showLoading({
            title: '加载中...',
        })
        let that = this;
        this._loadData(); //页面加载数据
        this.getCart()
    },

    onTabItemTap() {
        console.log('tab')
        wx.pageScrollTo({
            scrollTop: 0,
            duration: 200
        })
        this.onPullDownRefresh();
    },
    onShow() {
        let {
            title,
            changeType
        } = this.data
        this.setData({
            isVip: wx.getStorageSync('userStatus'),
            needShow: wx.getStorageSync('needShow') == home.nowV ? false : true  
        })
        if (changeType) {
            wx.setNavigationBarTitle({
                title
            })
        }
    },
    _loadData(cb) {
        console.log("页面数据加载");
        // 页面数据加载
        let that = this;
        let {
            storeNo,
            activeId
        } = this.data
        let params = {
            storeNo,
            activityId: '' + activeId
        }
        // 加载是否有优惠券
        home.getActivityCoupon(params, res => {
            if (res.status) {
                this.setData({
                    hasCoupon: res.data
                })
            }
        })
        //获取活动列表接口
        this.getActList();

        cb && cb();
    },
    //活动加载
    getActList() {
        let that = this;
        let { activeId } = this.data;
        let parames = {
            id: '' + activeId
        }
        home.getActivityDetail(parames, res => {
            if (res.status) {
                let nowActivity = res.data;
                app.aldstat.sendEvent('专场页面', {
                    "专场": nowActivity.name
                });
                wx.setNavigationBarTitle({
                    title: nowActivity.name
                })
                let noticeLen = nowActivity.notice.length;
                console.log("noticeLen", noticeLen)
                let animationTime = 0;
                if (noticeLen > 20) {
                    animationTime = parseInt(noticeLen / 3);
                }
                nowActivity.notice = nowActivity.notice ? nowActivity.notice.replace(/[\n]/ig, '') : '';
                if (nowActivity && nowActivity.imageActivityList) {
                    nowActivity.imageActivityList = nowActivity.imageActivityList.split(",");
                }

                that.setData({
                    nowActivity: nowActivity ? nowActivity : res.data[0],
                    animationTime
                })

                // 加载商品列表
                that.getGoodsList();
            }

        });
    },
    // 加载商品列表
    getGoodsList(cb) {
        let that = this;
        let storeNo = this.data.storeNo || wx.getStorageSync("storeNo");
        let {
            nowActivity,
            page,
            size,
            activityGoodsList
        } = this.data;

        let activityId = this.data.activeId;

        let parames = {
            "storeNo": storeNo,
            "activityId": activityId,
            "page": page,
            "size": size,
        }

        home.getGoodsList(parames, res => {
            wx.hideLoading()

            if (res.status) {
                this.setData({
                    first: true,
                })

                if (res.data.length > 0) {
                    console.log("goodList", res.data);
                    that.setData({
                        hasMore: true,
                        newWorkTimeOut: false
                    });

                    if (page + 1 > Math.ceil(res.total / size)) {
                        that.setData({
                            hasMore: false
                        });
                    }

                    let data = res.data.length > 0 ? res.data : [];
                    console.log('goodsList', data)
                    data.forEach((val, index) => {
                        let total = 0;
                        val.totalPrice = Number(val.discount_price) + Number(val.purchase_cost)
                        val.newDiscount = Math.round(val.member_price / val.goods_price * 100) / 10
                        val.goodsSize.forEach((value) => {
                            total += parseInt(value.stockNum);
                        })
                        val.nowTime = new Date().getTime()
                        val.sellOut = total;
                    })

                    let goodsList = "";
                    if (this.data.dropDown) {
                        goodsList = data;
                    } else {
                        goodsList = [...activityGoodsList, ...data];
                    }

                    this.setData({
                        activityGoodsList: goodsList,
                        dropDown: false
                    })
                    cb && cb();

                } else {
                    that.setData({
                        hasMore: false,
                        activityGoodsList: [],
                        dropDown: false
                    });
                }
                that.setData({
                    goodsHide: true
                });
            } else {
                wx.showToast({
                    title: res.message,
                    icon: 'none'
                })
            }

        });

    },
    //统计产品数量
    getGoodsCategoryCount(categoryId) {
        let that = this;
        let parames = {
            "categoryId": "" + categoryId
        };
        home.getGoodsCategoryCount(parames, res => {

            if (res.status) {
                console.log(res.data);
                that.setData({
                    categoryCount: res.data
                })
            }

        });
    },

    //获取用户权限设置
    _getAuthorize(callback) {
        var that = this;
        var userInfo = this.data.userInfo;
        if (!userInfo) {
            app.getUserSetting(res => { // 获取用户权限设置
                callback && callback();
            });
        } else {
            callback && callback();
        }
    },

    //跳转到商品详情页面
    onProductDetail(e) {
        let id = home.getDataSet(e, "id");
        let storeNo = this.data.storeNo;
        let userInfo = wx.getStorageSync('sessionId');
        if (userInfo) {
            wx.navigateTo({
                url: "/pages/product/product?id=" + id + "&storeNo=" + storeNo
            })
        } else {
            wx.navigateTo({
                url: '/pages/login/login'
            })
        }
    },
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {
        wx.showNavigationBarLoading(); //在标题栏中显示加载图标
        // this.render.clearArr();
        wx.showLoading({
            title: '加载中...',
        })
        let that = this;
        this.setData({
            page: 1,
            hasMore: false,
            dropDown: true
        })

        this._loadData(() => {
            wx.hideNavigationBarLoading();
            wx.stopPullDownRefresh(); //停止下拉刷新

            let {
                activityList,
                nowActivity
            } = this.data;
            let id = nowActivity.id;
            activityList.forEach((val) => {
                if (val.id == id) {
                    nowActivity = val
                }
            })

            this.setData({
                scrollNav: "nav" + nowActivity.id,

            })
        })
    },

    /**
     * 页面上拉触底事件的处理函数
     */

    onReachBottom: function() {
        var {
            page,
            hasMore
        } = this.data;

        /**
         * 此处加上数据大小的判断
         */

        if (hasMore) {
            this.setData({
                page: page + 1
            })
            this.getGoodsList();
        }

    },
    /**
     * 用户点击右上角分享
     */

    onShareAppMessage: function (e) {
        console.log(e)
        
        let that = this;
        app.aldstat.sendEvent(that.data.nowActivity.name + '分享');
        wx.showShareMenu({
            withShareTicket: true
        });
        let phone = wx.getStorageSync('phone'),
            invitePhone = wx.getStorageSync('invitePhone'),
            inviteDaigoCode = wx.getStorageSync('inviteDaigoCode'),
            ownInviteCode = wx.getStorageSync('ownInviteCode'),
            userStatus = wx.getStorageSync('userStatus'),
            // 如果自己是代购以上身份就用自己邀请码，否则是上游邀请码
            nowInviteCode = userStatus > 1 ? ownInviteCode : inviteDaigoCode,
            path = '',
            title = that.data.nowActivity.name,
            baseUrl = '/pages/home/home',
            activeId = this.data.activeId,
            url = '';
            console.log("分享的", phone, inviteDaigoCode, ownInviteCode)
            if ((!userStatus || userStatus === 0) && nowInviteCode) {
                path = `&inviteDaigoCode=${nowInviteCode}`
            } else if (userStatus === 1) {
                path = `&invitePhone=${phone}`
            } else if (userStatus > 1) {
                path = `&inviteDaigoCode=${nowInviteCode}`
            }
            if (e.from === 'button'){
                let {id,price,name,img} = e.target.dataset
                baseUrl = '/pages/product/product'
                activeId = id
                title = name +' 会员价:￥'+ price
                url = img.url
             }
        return {
            title: title, //storeInfo.brandName,
            path: `${baseUrl}?id=${activeId}${path}`,
            imageUrl: url,
            success: res => {
                if (res.shareTickets) {
                    console.log(res.shareTickets);
                    wx.getShareInfo({
                        shareTicket: res.shareTickets[0],
                        success: d => {
                            console.log(d);
                        }
                    })
                }
            }
        }
    },
    //打开搜索
    onSearch() {
        this.setData({
            searchShow: true,
            searchForm: true,
            searchVal: ""
        })
    },
    //关闭搜索
    onSearchClose() {
        this.setData({
            searchShow: false,
            searchForm: false,
            goodsListShow: false
        })
    },
    //搜索
    searchForm(e) {
        console.log(e.detail.value);
        let that = this;
        let {
            storeNo,
            activityList,
            nowActivity
        } = this.data;
        let searchName = e.detail.value.searchName;
        let activityId = nowActivity.id;
        activityList.forEach(val => {
            if (val.selected) {
                activityId = val.id;
            }
        })

        let params = {
            "searchName": '' + searchName,
            "activityId": '' + activityId
        }
        home.searchActivityGoodsList(params, res => {
            let status = res.status;
            let data = res.data;
            if (status) {
                if (data.length != 0) {
                    this.setData({
                        searchForm: false,
                        goodsListShow: true,
                        searchActivityGoodsList: data
                    })
                } else {
                    wx.showToast({
                        title: '未找到商品',
                        icon: 'none'
                    })
                }
            }
        })

    },
    //nav点击切换
    navChange(e) {
        let index = home.getDataSet(e, "index");
        let {
            activityList,
            scrollNav,
            nowActivity
        } = this.data;
        let id = activityList[index].id;

        activityList.forEach((val, i) => {
            if (i == index) {
                val.selected = true;
                nowActivity = val;
            } else {
                val.selected = false;
            }
        })
        wx.showNavigationBarLoading(); //在标题栏中显示加载图标
        this.setData({
            activityList,
            scrollNav: "nav" + id,
            nowActivity,
            page: 1,
            hasMore: false,
            dropDown: true
            // goodsHide: false,
            // activityGoodsList: []
        })
        this.getGoodsList(() => {
            wx.pageScrollTo({
                scrollTop: 0,
                duration: 0
            })
            wx.hideNavigationBarLoading();
        });

    },
    //点击查看大图
    preview(e) {
        let {
            activityGoodsList,
            nowActivity
        } = this.data;
        let curImg = home.getDataSet(e, "img");
        let images = [];
        if (home.getDataSet(e, "key") == 'activity') {
            images = nowActivity.imageActivityList
        } else {
            let index = home.getDataSet(e, "index");
            activityGoodsList[index].goodsImages.forEach(val => {
                if (val.url && val.url != "") {
                    images.push(val.url);
                }
            })
        }
        // console.log("images----------------", images);
        if (images && images.length > 0) {
            wx.previewImage({
                current: curImg,
                urls: images
            })
        }
    },

    //存图
    existImg(e) {
        let that = this
        let taggle = [];
        let failPath = []
        wx.getSetting({
            success: (res) => {
                console.log(Object.keys(res.authSetting).indexOf('scope.writePhotosAlbum'))
                if (Object.keys(res.authSetting).indexOf('scope.writePhotosAlbum') < 0 || res.authSetting["scope.writePhotosAlbum"]) {
                    wx.showToast({
                        title: '图片保存中',
                        icon: 'loading'
                    })
                    console.log(this.data.shareTempFilePath)
                    let index = home.getDataSet(e, 'index');
                    let {
                        activityGoodsList
                    } = that.data;

                    activityGoodsList[index].goodsImages.forEach((val, i) => {
                        if (val.url && val.url != "") {
                            console.log(val.url)
                            wx.downloadFile({
                                url: val.url,
                                success: function(res) {
                                    let path = res.tempFilePath
                                    console.log('path', path)
                                    wx.saveImageToPhotosAlbum({
                                        filePath: path,
                                        success(res) {
                                            console.log("存图--------------------");
                                            console.log(res);
                                            taggle.push(true);
                                        },
                                        fail(res) {
                                            // wx.hideLoading()
                                            failPath.push(path)
                                            console.log('存图失败', res, val.url)
                                            setTimeout(() => {
                                                wx.saveImageToPhotosAlbum({
                                                    filePath: path,
                                                    success(res) {
                                                        console.log('重新存图成功')
                                                        taggle.push(true)
                                                        let newTag = taggle.filter((val) => {
                                                            return val == true
                                                        })
                                                        if (newTag.length === activityGoodsList[index].goodsImages.length) {
                                                            wx.showToast({
                                                                title: '图片信息已复制',
                                                                icon: 'success'
                                                                // duration: 250
                                                            })
                                                        }
                                                    },
                                                    fail(res) {
                                                        console.log('重新存图失败', res)
                                                    }
                                                })
                                            }, 1000)
                                            taggle.push(false);
                                        },
                                        complete(res) {
                                            let tag = taggle.filter(val => {
                                                return val == false;
                                            })
                                            console.log(tag, val, "====", activityGoodsList[index].goodsImages.length, "...", taggle.length)
                                            if (tag.length == 0 && i == activityGoodsList[index].goodsImages.length - 1) {

                                                // wx.hideLoading()
                                                wx.showToast({
                                                    title: '图片信息已复制',
                                                    icon: 'success'
                                                    // duration: 250
                                                })

                                                setTimeout(function() {
                                                    wx.hideLoading()
                                                }, 500)
                                            } else if (tag.length != 0) {
                                                // wx.showToast({
                                                //   title: '第'+ Number(i+1) +'张图片保存失败，正在重新保存',
                                                //   icon: 'none',
                                                // })
                                            }

                                        }
                                    })
                                },
                                fail: function(res) {
                                    console.log('图片下载失败', res, val.url)
                                }
                            })
                        }
                    })
                    console.log('failPath', failPath)
                    failPath.length > 0 && failPath.forEach(val => {
                        wx.saveImageToPhotosAlbum({
                            filePath: val,
                            success(res) {
                                //   wx.showToast({
                                //       title: '第' + Number(i + 1) + '张图片保存失败，',
                                //       icon: 'success',
                                //   })
                                console.log('重新存图成功')
                            },
                            fail(res) {
                                console.log('重新存图失败')
                            }
                        })
                    })
                } else {
                    wx.showModal({
                        title: '提示',
                        content: '存图权限未开启，点击开启？',
                        success(res) {
                            if (res.confirm) {
                                wx.openSetting({

                                })
                            }
                        }
                    })
                }
            }
        })

    },
    //加入购物车
    addCartShow(e) {

        let index = home.getDataSet(e, 'index');
        let list = home.getDataSet(e, 'list');
        let newGoodsList = null;
        let {
            activityGoodsList,
            searchActivityGoodsList
        } = this.data;
        switch (list) {
            case "activityGoodsList":
                newGoodsList = activityGoodsList[index]
                break;
            case "searchActivityGoodsList":
                newGoodsList = searchActivityGoodsList[index]
                break;
        }
        //选中尺寸
        let goodsSize = this.canSizeVaild(newGoodsList)

        this.setData({
            newGoodsList: newGoodsList,
            addCartShow: true,
            searchShow: false,
            searchForm: false,
            goodsListShow: false,
            "cartParams.ctrnum": 1,
            "cartParams.goodsSize": goodsSize
        })
    },
    //隐藏加入购物车弹框
    addCartHide(e) {
        this.setData({
            addCartShow: false
        })
    },
    //点击商品颜色
    onColorOption(e) {
        let goodsId = home.getDataSet(e, "id");
        let storeNo = this.data.storeNo;
        let that = this;
        let params = {
            "goodsId": "" + goodsId
        }
        home.getGoodsById(params, res => {
            let status = res.status;
            let data = res.data;

            //选中尺寸
            let goodsSize = that.canSizeVaild(data)
            if (status) {
                that.setData({
                    "newGoodsList": data,
                    "cartParams.goodsSize": goodsSize
                })
            }
        });
    },
    //选择商品尺寸
    onSizeOption(e) {
        let goodsSize = home.getDataSet(e, "key");
        let {
            cartParams
        } = this.data;
        let ctrnum = cartParams.ctrnum;
        let stockNum = goodsSize.stockNum;
        let oldGoodsSize = cartParams.goodsSize;
        if (stockNum && ctrnum > stockNum) {
            ctrnum = stockNum;
        }
        if (oldGoodsSize && goodsSize.id == oldGoodsSize.id) {
            goodsSize = null;
        }

        if (goodsSize != "") {
            this.setData({
                "cartParams.goodsSize": goodsSize,
                "cartParams.ctrnum": ctrnum
            })
        }
    },
    //数量减
    onNumMinus(e) {
        let {
            cartParams
        } = this.data;
        if (!cartParams.goodsSize || cartParams.goodsSize == "") {
            wx.showToast({
                title: '请选择商品尺寸',
                icon: 'none'
            })
            return;
        }
        let ctrnum = cartParams.ctrnum;
        if (cartParams.ctrnum > 1) {
            ctrnum--;
            this.setData({
                "cartParams.ctrnum": ctrnum
            })
        }
    },
    //数量加
    onNumAdd(e) {
        let {
            cartParams
        } = this.data;
        if (!cartParams.goodsSize || cartParams.goodsSize == "") {
            wx.showToast({
                title: '请选择商品尺寸',
                icon: 'none'
            })
            return;
        }
        let ctrnum = cartParams.ctrnum;
        console.log(ctrnum)
        if (ctrnum < cartParams.goodsSize.stockNum) {
            ctrnum++;
            this.setData({
                "cartParams.ctrnum": ctrnum
            })
        } else if (ctrnum >= cartParams.goodsSize.stockNum) {
            console.log("数量添加到极限")
        }

    },
    //加入购物车
    addCart(e) {
        app.aldstat.sendEvent('专场-加入购物车', {
            '专场': this.data.nowActivity.name
        });
        let {
            newGoodsList,
            nowActivity,
            cartParams,
            isVip,
            cartNum
        } = this.data;
        let that = this;
        // 判断尺码是否为空
        if (cartParams.goodsSize == null) {
            wx.showToast({
                title: '请选择尺寸',
                icon: 'none'
            })
            return;
        }

        //判断数值
        if (cartParams.ctrnum <= 0) {
            wx.showToast({
                title: '请添加数量',
                icon: 'none'
            })
            return;
        }
        let goodsId = newGoodsList.goods_id || newGoodsList.goodsId;
        let goodsName = newGoodsList.goods_name || newGoodsList.goodsName
        let goodsPrice = isVip == 0 ? (newGoodsList.discount_price || newGoodsList.discountPrice) :
            (((newGoodsList.member_price || newGoodsList.memberPrice) && (newGoodsList.member_price || newGoodsList.memberPrice) != '') ? (newGoodsList.member_price || newGoodsList.memberPrice) : (newGoodsList.discount_price || newGoodsList.discountPrice))
        let goodsColor = newGoodsList.goods_color || newGoodsList.goodsColor
        let goodsPic = newGoodsList.goods_pic || newGoodsList.goodsPic
        let originalPrice = newGoodsList.goods_price || newGoodsList.goodsPrice
        let discountPrice = newGoodsList.discount_price || newGoodsList.discountPrice

        let params = {
            "goodsId": "" + goodsId,
            "goodsName": "" + goodsName,
            "goodsNum": "" + cartParams.ctrnum,
            "goodsPrice": "" + goodsPrice,
            "goodsColor": "" + goodsColor,
            "specsName": "" + cartParams.goodsSize.specsName,
            "goodsPic": "" + goodsPic,
            "originalPrice": "" + originalPrice,
            "activityId": "" + nowActivity.id,
            "discountPrice": "" + discountPrice,

        }
        if (isVip > 0) {
            params.memberPrice = "" + (newGoodsList.member_price || newGoodsList.memberPrice)
        }
        console.log(params);
        if (newGoodsList.soldout == 0) {

            home.getAddCart(params, res => {
                let status = res.status;
                let data = res.data;
                if (status) {
                    wx.showToast({
                        title: '加入购物车成功',
                        icon: 'none'
                    })
                    this.setData({
                        cartNum: cartNum + Number(cartParams.ctrnum)
                    })
                    // this.getCart();
                    setTimeout(function() {
                        that.addCartHide();
                    }, 400);
                } else {
                    wx.showToast({
                        title: '添加失败',
                        icon: 'none'
                    })
                }
            })
        }

    },
    showImg(e) {
        //查看大图
        let imgurl = home.getDataSet(e, "img");
        let imgurls = [];
        imgurls.push(imgurl);
        if (imgurls && imgurls.length > 0) {
            wx.previewImage({
                current: imgurl,
                urls: imgurls
            })
        }
    },
    //去购物车
    goCart(e) {
        wx.switchTab({
            url: '/pages/cart/cart'
        })
    },
    // 跳转购买会员页
    jumpOrdinary() {
        let {
            activeId
        } = this.data
        let phone = wx.getStorageSync("phone");
        if (phone === "") {
            wx.navigateTo({
                url: '/pages/signin/signin?path=/pages/role/ordinary/ordinary',
            })
        } else {
            wx.navigateTo({
                url: '/pages/role/ordinary/ordinary',
            })
        }
    },
    getCart() {
        let that = this;
        let {
            storeNo
        } = this.data;
        let parames = {
            "storeNo": '' + storeNo
        }
        home.getCart(parames, res => {
            if (res.status) {
                let total = 0;
                res.data.forEach((value, index) => {
                    value.list.forEach((val, index) => {
                        total += parseInt(val.goodsNum);
                    });
                })
                this.setData({
                    cartNum: total
                })
            }
        })

    },

    // 检测当前尺寸是否可用
    canSizeVaild(data) {
        let goodsSize;
        let thatSizes = data.goodsSize ? data.goodsSize : data.goodsStock;

        if (thatSizes[0].stockNum > 0) {
            goodsSize = thatSizes[0];
        } else {
            for (let i = 0; i < thatSizes.length; i++) {
                if (thatSizes[i].stockNum > 0) {
                    goodsSize = thatSizes[i];
                    break;
                } else {
                    goodsSize = ""
                }
            }

        }
        return goodsSize;
    },
    // 播放视频
    showVideo(e) {
        let index = home.getDataSet(e, 'index')
        let url = this.data.activityGoodsList[index].videoUrl
        this.setData({
            nowVideo: url
        })
        this.videoContext.requestFullScreen({
            direction: 0
        })
        this.videoContext.play()
    },
    // 监听视频全屏
    bindfullscreenchange(e) {
        console.log(e.detail)
        if (e.detail.fullScreen) {
            this.videoContext.play()
        } else {
            this.videoContext.pause()
        }
    },
    // 视频退出全屏
    outFullScreen() {
        this.videoContext.pause()
        this.videoContext.exitFullScreen()
    },


})